import { IAssemblyDocTreeNode } from '@amcax/base';
import { createContext, useContext } from 'react';

export const DocumentContext = createContext<{
  workingObjectDxid?: string;
  docTree?: IAssemblyDocTreeNode & { documentInfo: CadDocument.DocumentInfo };
  documentInfo?: CadDocument.DocumentInfo;
}>({});

export const useDocumentConsumer = () => {
  const context = useContext(DocumentContext);
  if (!context) {
    throw new Error(
      'useDocumentConsumer must be used within a DocumentProvider',
    );
  }
  return context;
};
